package com.game.gui {
	import com.game.data.Data;
	import com.game.utils.TowerType;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.filters.BlurFilter;
	import flash.text.TextField;
	import flash.text.TextFormat;
	public class TowerSelectionButton extends Sprite {
		private var _type:TowerType = TowerType.NONE;
		private var txt:TextField;
		private var _cost:int = 0;
		private var _onShape:Shape = new Shape();
		public function TowerSelectionButton(type:TowerType, bmp:BitmapData = null, format:TextFormat = null, cost:int = 10) {
			_type = type;
			_cost = cost;
			this.graphics.clear();
			if (bmp) {
				this.graphics.beginBitmapFill(bmp,null,false,true);
			} else {
				this.graphics.lineStyle(3, 0)
				this.graphics.beginFill(0xcccccc, 1);
			}
			txt = new TextField();
			txt.defaultTextFormat = format;
			addChild(txt);
			txt.embedFonts = true;
			txt.width = Data.ICON_SIZE - 2;
			txt.height = 22;
			txt.selectable = false;
			txt.text = String(_cost) + "$";
			txt.mouseEnabled = false;
			txt.y = Data.ICON_SIZE - txt.height;
			this.graphics.drawRect(0, 0, Data.ICON_SIZE, Data.ICON_SIZE);
			this.graphics.endFill();
			this.mouseChildren = false;
			this.buttonMode = true;
			//
			var sz:int = Data.ICON_SIZE - 18;
			this._onShape.x = 9
			this._onShape.y = 9
			this._onShape.graphics.lineStyle(3, 0xFF9900);
			this._onShape.graphics.moveTo(sz / 2, sz);
			this._onShape.graphics.curveTo(0, sz, 0, sz / 2);
			this._onShape.graphics.curveTo(0, 0, sz / 2, 0);
			this._onShape.graphics.curveTo(sz, 0, sz, sz / 2);
			this._onShape.graphics.lineTo(sz - 1, sz / 2 + 10);
		}
		public function over(value:Boolean):void {
			if (_onShape.stage) {
				this.removeChild(_onShape);
			}
			_onShape.filters = []
			if (value) {
				this.addChild(_onShape);
				_onShape.filters = [new BlurFilter(5, 5, 2)]
			}
		}
		public function get type():TowerType {
			return _type;
		}
		public function set type(value:TowerType):void {
			_type = value;
		}
	}
}